package com.cai.mvvm.ui.activity;

import android.Manifest;
import android.view.View;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.cai.mvvm.R;
import com.cai.mvvm.adapter.ItemAdapter;
import com.cai.mvvm.databinding.MainBind;
import com.cai.mvvm.viewmodel.MainViewModel;
import com.mvvm.library.base.BaseActivity;
import com.mvvm.library.common.RouterConstant;
import com.mvvm.library.permission.AndroidPermission;
import com.mvvm.library.util.ToastUtil;


@Route(path = RouterConstant.APP_MAIN)
public class MainActivity extends BaseActivity<MainBind, MainViewModel> {

    @Override
    protected int getLayoutId() {
        return R.layout.activity_main;
    }

    @Override
    protected void initView() {
        binding.setData(viewModel);
        ItemAdapter itemAdapter = new ItemAdapter();
        binding.list.setAdapter(itemAdapter);
        viewModel.data.observe(this, s -> {
            //TODO 观察着模式
            binding.setData(viewModel);
        });
        viewModel.data.observe(this, s -> {
            //TODO 观察着模式
            binding.setData(viewModel);
        });

        viewModel.setList();
        viewModel.setData();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_arouter:
                ARouter.getInstance()
                        .build(RouterConstant.HOME_MAIN)
                        .navigation(mContext);
                break;
            case R.id.btn_permission:
                goHome();
                break;
        }
    }
    @AndroidPermission(permissions = {Manifest.permission.WRITE_EXTERNAL_STORAGE,// 写入权限
            Manifest.permission.READ_EXTERNAL_STORAGE,  //读取权限
            Manifest.permission.READ_PHONE_STATE,  //读取设备信息
            Manifest.permission.ACCESS_FINE_LOCATION,//定位权限
            Manifest.permission.INTERNET,//网络权限
            Manifest.permission.CAMERA,//拍摄权限
            Manifest.permission.BLUETOOTH,
            Manifest.permission.BLUETOOTH_ADMIN,
            Manifest.permission.RECORD_AUDIO//录音权限
    })
    public void goHome(){
        ToastUtil.showToast("权限申请通过");
    }
}